﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using IpProxyLibrary;

namespace IpProxy
{
    public partial class FormSettings : Form
    {
        FormSettingsModel model = new FormSettingsModel();

        SettingsBean mSettingsBean;

        public FormSettings()
        {
            InitializeComponent();
        }

        private void btConfirm_Click(object sender, EventArgs e)
        {
            if (txtProxyUrl.Text == "")
            {
                MessageBox.Show("url地址不能为空","提示");
                return;
            }

            if (cbxActivate.Checked)
            {
                model.InternetSetOption(txtProxyUrl.Text);
                MessageBox.Show("代理url设置完成", "提示");
            }
            else
            {
                model.InternetSetOption(null);
                MessageBox.Show("代理url取消完成", "提示");
            }

            if (mSettingsBean == null)
            {
                mSettingsBean = new SettingsBean();
            }
            mSettingsBean.Actived = cbxActivate.Checked;
            mSettingsBean.ProxyUrl = txtProxyUrl.Text;
            FileCache.getInstance().save(mSettingsBean);
            this.Close();

        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormSettings_Load(object sender, EventArgs e)
        {
            mSettingsBean = FileCache.getInstance().load <SettingsBean>();
            cbxActivate.Checked = mSettingsBean.Actived;
            txtProxyUrl.Text = mSettingsBean.ProxyUrl;
        }
    }
}
